package Application.Controller;

import Application.AppJoint;
import Application.Layer.Layer;
import Application.Layer.LayerDelegate;
import Application.StatusBarManager.StatusBarManager;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;


public class RenameBoxController extends Controller {
    @FXML
    TextField textRename;

    public void comfirmedBtnOnAction(){
        String name = textRename.getText();
        if(name.equals("")){
            StatusBarManager.getInstance().setText("你还没有输入名字！");
            return;
        }

        int id = AppJoint.getInstance().getActiveLayerId();

        int index = LayerDelegate.getInstance().getIndexGivenId(id);

        Layer layer = LayerDelegate.getInstance().getLayers().get(index);
        layer.setName(name);

        Label label = (Label)layer.getRoot().getChildren().get(1);

        label.setText(name);

        //关闭输入款
        MainWindowController mainWindowController = AppJoint.getInstance().getMainWindowController();
        VBox vBox = mainWindowController.getVboxToolBar();

        vBox.getChildren().remove(1);
        AppJoint.getInstance().setRenameBoxActivited(false);
    }

}
